{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "from wordcloud import WordCloud\n",
    "import jieba\n",
    "\n",
    "text_from_file_with_apath = open(r'../data/评论.txt',encoding='utf-8').read()\n",
    "\n",
    "# 增加自定义词典，用来定义不想被分割的内容\n",
    "jieba.add_word('比心')\n",
    "wordlist_after_jieba = jieba.cut(text_from_file_with_apath, cut_all = True)\n",
    "wl_space_split = \" \".join(wordlist_after_jieba)\n",
    "# 停用词，即不想出现在词云图中的内容\n",
    "stopwords=['了','在','个','上','吗']\n",
    "\n",
    "my_wordcloud = WordCloud(\n",
    "  # 确保字体文件存在，具体查找字体文件的方法为（Windows：c:\\windows\\fonts找到合适的字体，在字体图标上按右键可得到准确的字体文件。\n",
    "  font_path='c:\\windows\\fonts\\SourceHanSerifSC-Heavy.otf',\n",
    "  background_color='white',\n",
    "  stopwords=stopwords,\n",
    "  width=1200,\n",
    "  height=900\n",
    "  ).generate(wl_space_split)\n",
    "\n",
    "# 更改图像大小\n",
    "# plt.rcParams[\"figure.figsize\"]=(3.487,1.618)\n",
    "plt.rcParams[\"figure.dpi\"] = 300\n",
    "\n",
    "plt.imshow(my_wordcloud)\n",
    "plt.axis(\"off\")\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
